package com.elitetyc.eliteim.common.util;

import cn.hutool.core.date.DateUtil;
import com.elitetyc.eliteim.common.constant.Constants;
import com.elitetyc.eliteim.common.model.impl.U2UMsg;
import com.elitetyc.eliteim.common.model.impl.UserLoginData;
import com.elitetyc.eliteim.common.proto.RequestProto;

import java.util.Date;

/**
 * @author yuanchao.tan
 * @version 1.0
 * @description TODO
 * @Date 2021/9/17 16:15
 */
public class MsgUtil {
    public static String userName="default";

    public static RequestProto.RequestProtocol buildMsg(int type,String rid,String data){
        return RequestProto.RequestProtocol.newBuilder()
                .setRId(rid)
                .setData(data)
                .setType(type).build();
    }

    public static RequestProto.RequestProtocol buildMsg(int type){
        return buildMsg(type,Constants.DEFAULT_RID,Constants.DEFAULT_SUCCESS_MSG);
    }

    public static RequestProto.RequestProtocol buildMsg(int type,String data){
        return buildMsg(type,Constants.DEFAULT_RID,data);
    }

    public static void echoMsg(String msg){
        Constants.defaultMsgTemplateFormat(DateUtil.now(),userName,msg);
    }

    /**
     * 创建对点的文本消息
     * @param receiveUserId
     * @param content
     * @return
     */
    public static U2UMsg buildU2UStrMsg(String receiveUserId, String content) {
        final U2UMsg u2UMsg = new U2UMsg();
        u2UMsg.sender = UserInfoHolder.user;
        u2UMsg.msgType = Constants.MsgType.STRING;
        u2UMsg.content = content;
        u2UMsg.receiveId = receiveUserId;
        u2UMsg.sendTime = new Date();
        return u2UMsg;
    }

    /**
     * 创建用户登陆的消息
     * @param userId
     * @param userName
     * @return
     */
    public static UserLoginData buildLoginMsg(String userId,String userName){
        MsgUtil.userName = userName;
        final UserLoginData loginData = new UserLoginData();
        loginData.setUserId(userId);
        loginData.setUserName(userName);
        return loginData;
    }
}
